/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Campeonatos.java
 *
 * Created on 27/06/2011, 03:41:08
 */
package GUI.relatorios;

import javax.swing.table.DefaultTableModel;
import util.MySqlTableModel;

/**
 *
 * @author Gabriel
 */
public class Campeonatos extends javax.swing.JFrame {

    /** Creates new form Campeonatos */
    public Campeonatos() {
        initComponents();
        this.setLocationRelativeTo(null);
        String colunas[] = {"Nome", "Participações", "Primeira Participação"};
        String query = "SELECT escola.nomeCompleto, COUNT(campeonato_estadual.idCampeonato), MIN(campeonato_estadual.anoRealizacao) "
                + "FROM escola JOIN (escola_participante,campeonato_estadual) "
                + "ON (escola.idEscola = escola_participante.idEscola AND escola_participante.idCampeonato = campeonato_estadual.idCampeonato) "
                + "GROUP BY escola.nomeCompleto "
                + "HAVING SUM(campeonato_estadual.idCampeonato) > 1";
        query = "(SELECT escola.nomeCompleto,COUNT(escola_participante.idCampeonato),MIN(campeonato_estadual.anoRealizacao) as N FROM escola_participante JOIN escola ON escola_participante.idEscola=escola.idEscola JOIN campeonato_estadual ON escola_participante.idCampeonato=campeonato_estadual.idCampeonato GROUP BY escola_participante.idEscola HAVING COUNT(escola_participante.idCampeonato) > 1)";
        System.out.println(query);

        jTable1.setModel(new MySqlTableModel(query, colunas));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados"));

        jTable1.setModel(new DefaultTableModel());
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Campeonatos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
